package cn.edu.lcu.cs.javaprogramming.net;

import cn.edu.lcu.cs.javaprogramming.BaseTest;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import java.io.IOException;
import java.net.FileNameMap;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;

/**
 * @author ling
 * @date 2022/5/30 8:32
 */
public class URLDemo extends BaseTest {

    @ParameterizedTest
    @CsvSource({"http://ee-c.lcu.edu.cn/static/images/hwImages/huaweiyunLogo.png", "https://gitee.com/linghy/java-programming/blob/594288b68720099fede40f43dd7eb53834aca6fd/java-2022-1/src/main/java/cn/edu/lcu/cs/javaprogramming/db/DBUtil.java#L13"})
    void httpConnection(String urlString) throws IOException {
        URL url = new URL(urlString);
        System.out.println("url = " + url);
        System.out.println("url.getPath() = " + url.getPath());
        System.out.println("url.getFile() = " + url.getFile());
        System.out.println("url.getQuery() = " + url.getQuery());
        System.out.println("url.getRef() = " + url.getRef());
        System.out.println("url.getContent().getClass().getName() = " + url.getContent().getClass().getName());

        URLConnection connection = url.openConnection();
        System.out.println("connection.getContentType() = " + connection.getContentType());
        System.out.println("connection.getContentLength() = " + connection.getContentLength());
    }
}
